package com.ruoyi.web.controller.pcapp;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.app.domain.AppCaseReceipt;
import com.ruoyi.app.service.IAppCaseReceiptService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案件回执Controller
 * 
 * @author ruoyi
 * @date 2019-12-13
 */
@Controller
@RequestMapping("/pc/receipt")
public class PcCaseReceiptController extends BaseController
{
    private String prefix = "app/receipt";

    @Autowired
    private IAppCaseReceiptService appCaseReceiptService;

    @RequiresPermissions("app:receipt:view")
    @GetMapping()
    public String receipt()
    {
        return prefix + "/receipt";
    }

    /**
     * 查询案件回执列表
     */
    @RequiresPermissions("app:receipt:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppCaseReceipt appCaseReceipt)
    {
        startPage();
        List<AppCaseReceipt> list = appCaseReceiptService.selectAppCaseReceiptList(appCaseReceipt);
        return getDataTable(list);
    }

    /**
     * 导出案件回执列表
     */
    @RequiresPermissions("app:receipt:export")
    @Log(title = "案件回执", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppCaseReceipt appCaseReceipt)
    {
        List<AppCaseReceipt> list = appCaseReceiptService.selectAppCaseReceiptList(appCaseReceipt);
        ExcelUtil<AppCaseReceipt> util = new ExcelUtil<AppCaseReceipt>(AppCaseReceipt.class);
        return util.exportExcel(list, "receipt");
    }

    /**
     * 新增案件回执
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存案件回执
     */
    @RequiresPermissions("app:receipt:add")
    @Log(title = "案件回执", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppCaseReceipt appCaseReceipt)
    {
        return toAjax(appCaseReceiptService.insertAppCaseReceipt(appCaseReceipt));
    }

    /**
     * 修改案件回执
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AppCaseReceipt appCaseReceipt = appCaseReceiptService.selectAppCaseReceiptById(id);
        mmap.put("appCaseReceipt", appCaseReceipt);
        return prefix + "/edit";
    }

    /**
     * 修改保存案件回执
     */
    @RequiresPermissions("app:receipt:edit")
    @Log(title = "案件回执", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppCaseReceipt appCaseReceipt)
    {
        return toAjax(appCaseReceiptService.updateAppCaseReceipt(appCaseReceipt));
    }

    /**
     * 删除案件回执
     */
    @RequiresPermissions("app:receipt:remove")
    @Log(title = "案件回执", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appCaseReceiptService.deleteAppCaseReceiptByIds(ids));
    }
}
